package sk.demo.springboot;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import sk.demo.domain.Message;
import sk.demo.persist.MessageMapper;

import java.util.Date;
import java.util.List;
import java.util.Random;

/**
 * @author sk.z
 */
@Service
public class MessageService {

    @Autowired
    private MessageMapper messageMapper;

    public List<Message> select() {
        List<Message> messages = messageMapper.selectAll();
        return messages;
    }

    public int save() {
        Random random = new Random();
        int r = random.nextInt(999);

        Message message = new Message();
        message.setUserId("10001");
        message.setTitle("title " + r);
        message.setContent("mybatis save " + r);
        message.setCreateTime(new Date());
        return messageMapper.insert(message);
    }
}
